<?php session_start();
require_once('Connections/db.php'); 

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  session_unregister('MM_Username');
  session_unregister('MM_UserGroup');
	
  $logoutGoTo = "index.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
  $updateSQL = sprintf("UPDATE zonas SET descripcion=%s WHERE cod_zona=%s",
                       GetSQLValueString($_POST['descripcion'], "text"),
                       GetSQLValueString($_POST['cod_zona'], "int"));

  mysql_select_db($database_db, $db);
  $Result1 = mysql_query($updateSQL, $db) or die(mysql_error());

  $updateGoTo = "zonas.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$cod_zona_qryzonas = "-1";
if (isset($_GET['cod_zona'])) {
  $cod_zona_qryzonas = (get_magic_quotes_gpc()) ? $_GET['cod_zona'] : addslashes($_GET['cod_zona']);
}
mysql_select_db($database_db, $db);
$query_qryzonas = sprintf("select * from zonas where %s = %s", $cod_zona_qryzonas,$cod_zona_qryzonas);
$qryzonas = mysql_query($query_qryzonas, $db) or die(mysql_error());
$row_qryzonas = mysql_fetch_assoc($qryzonas);
$totalRows_qryzonas = mysql_num_rows($qryzonas);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/menu.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="doctitle" -->
<title>Aduana</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function loadIframe( url) {
    location = url;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es requerido.\n'; }
  } if (errors) alert('Error:\n'+errors);
  document.MM_returnValue = (errors == '');
}
function gotofocus() {
	document.form2.descripcion.focus();
}
//-->
</script>
<!-- InstanceEndEditable --><!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<link href="aduana.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
<!-- 

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
 

//-->
</script>
<style type="text/css">
<!--
body {

}
.style1 {color: #FFFFFF}
-->
</style>
<!-- InstanceParam name="OptionalRegion1" type="boolean" value="true" --><!-- InstanceParam name="OptionalRegion2" type="boolean" value="true" --><!-- InstanceParam name="OptionalRegion3" type="boolean" value="true" -->
</head>

<body onLoad="gotofocus()">
<table width="720" height="100%" border="2" align="center" cellpadding="0" cellspacing="0" bordercolor="#333399">
  <tr>
    <td valign="top"><table width="780" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="600" valign="middle">&nbsp;</td>
        <td><table width="180" height="60" border="0" cellpadding="0" cellspacing="1" bgcolor="#757B93">
            <tr>
              <td bgcolor="#bdbdbd"><div align="center" class="logout_usr">
			    <?php if (isset($_SESSION['MM_Username'])) {
				?>
			    <a href="<?php echo $logoutAction ?>" class="logout_usr">
					<?php  echo 'logout: '.$_SESSION['MM_Username']; ?>
				  </a>			  	
			    <?php } else {?>
				  <a href="index.php" class="negritaBlanca">Login</a></div></td> 
			  <?php } ?>
            </tr>
            <tr>
              <td height="20" class="titulo_adm_actual"><!-- InstanceBeginEditable name="titulo_adm_actual" -->
                <div align="center">Zonas de Operaci&oacute;n </div>
              <!-- InstanceEndEditable --></td>
            </tr>
        </table></td>
      </tr>
    </table>
      
      <table width="780" height="20" border="0" cellpadding="0" cellspacing="1" bgcolor="#1B01A9">
        <tr bgcolor="#000099">
		<?php if (isset($_SESSION['MM_Username']) ) { 
			echo '<td bgcolor="#757B93">&nbsp;<a href="servicio_add.php" class="menu_principal">Servicios</a>&nbsp;| &nbsp;<a href="liquidaciones.php" class="menu_principal">Liquidaciones</a>&nbsp;| &nbsp;<a href="pagos.php" class="menu_principal">Pagos</a>&nbsp;| &nbsp;<a href="basicos.php" class="menu_principal">Tablas</a>&nbsp;| &nbsp;<a href="agentes.php" class="menu_principal">Agentes</a>&nbsp;| &nbsp; <a href="informes.php" class="menu_principal">Informes</a>&nbsp;| &nbsp; <a href="permisos.php" class="menu_principal">Seguridad</a> </td>';
		} else {  
			echo '<td bgcolor="#757B93" class="menu_principal">&nbsp;Servicios &nbsp;| &nbsp;Liquidaciones&nbsp;| &nbsp;Pagos&nbsp;| &nbsp;Despachantes&nbsp;| &nbsp;Operadores &nbsp;| &nbsp;Lugares &nbsp;| &nbsp;Agentes&nbsp;| &nbsp;Seguridad</td>';						
		}?>
		<td width="178" class="negritaBlanca style1"><div align="center">
              <SCRIPT language=JavaScript><!--
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
var now = new Date();
var textout; 
var month = now.getMonth();
var date = now.getDate();
var year = now.getYear();
if (month==0) textout="Enero";
if (month==1) textout="Febrero";
if (month==2) textout="Marzo";
if (month==3) textout="Abril";
if (month==4) textout="Mayo";
if (month==5) textout="Junio";
if (month==6) textout="Julio";
if (month==7) textout="Agosto";
if (month==8) textout="Septiembre";
if (month==9) textout="Octubre";
if (month==10) textout="Noviembre";
if (month==11) textout="Diciembre";
//textout += " " + date + ", " + y2k(year);
document.write (date + " de " + textout + " de " + y2k(year) );
// -->
</SCRIPT>
          </div></td>
        </tr>
      </table>
      <table width="780" height="400" border="0" cellpadding="0" cellspacing="1">
        <tr>
          <td width="140" valign="top" bgcolor="#999999"><table width="140" border="0" cellpadding="0" cellspacing="1" bgcolor="#bdbdbd">
             
              <!-- InstanceBeginEditable name="EditRegion4" -->
              <tr>
                <td height="20" bgcolor="#757B93" class="titulo_adm_actual"><div align="center">Modificaci&oacute;n</div></td>
              </tr>
              <tr>
                <td height="20" bgcolor="#999999">&nbsp; </td>
              </tr>
              <tr>
                <td height="20" bgcolor="#999999">&nbsp;</td>
              </tr>
              <tr> 
                <td height="20" bgcolor="#999999">&nbsp;</td>
              </tr>
              <!-- InstanceEndEditable -->
          </table>
          <br></td>
          <td valign="top" bgcolor="#FFFFFF"><!-- InstanceBeginEditable name="EditRegion1" -->
          <form action="<?php echo $editFormAction; ?>" method="post" name="form2" onSubmit="MM_validateForm('descripcion','','R');return document.MM_returnValue">
            <br>
            <table align="center">
              <tr valign="baseline">
                <td colspan="2" align="right" nowrap class="titulo_form_ingreso_datos"><div align="center">Modificar Zona</div></td>
                </tr>
              <tr valign="baseline">
                <td align="right" nowrap class="labels_ingreso_datos">Descripcion:</td>
                <td><input name="descripcion" type="text" class="cuadrodetexto" value="<?php echo $row_qryzonas['descripcion']; ?>" size="50" maxlength="50"></td>
              </tr>
              <tr valign="baseline">
                <td nowrap align="right">&nbsp;</td>
                <td><input type="submit" class="botones" value="Grabar">
                  <input name="Button" type="button" class="botones" value="Cancelar" onClick="return loadIframe('zonas.php')"></td>
              </tr>
            </table>
            <input type="hidden" name="cod_zona" value="<?php echo $row_qryzonas['cod_zona']; ?>">
            <input type="hidden" name="MM_update" value="form2">
            <input type="hidden" name="cod_zona" value="<?php echo $row_qryzonas['cod_zona']; ?>">
          </form>
          <p>&nbsp;</p>
          on1&#8226;<!-- InstanceEndEditable --></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($qryzonas);
?>
